package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-03-11
 * Time: 13:46
 */
public class Change implements Ioperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("请输入要修改的书名");
        Scanner scanner = new Scanner(System.in);
        String bookName = scanner.nextLine();
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            Book book = bookList.getBook(i);
            if (book.getName().equals(bookName)) {
                //找到了
                System.out.println("请输入修改后的书名");
                String newBookName = scanner.nextLine();

                System.out.println("请输入修改后的作者");
                String newBookAuthor = scanner.nextLine();

                System.out.println("请输入修改后的价格");
                Double newBookPrice = scanner.nextDouble();

                System.out.println("请输入修改后的类型");
                String newBookType = scanner.next();
                book.setName(newBookName);
                book.setAuthor(newBookAuthor);
                book.setPrice(newBookPrice);
                book.setType(newBookType);
                book.setBorrowed(false);
                System.out.println("修改成功!!!");
                return;
            }
            System.out.println("没有找到这本书!!!");
        }
    }
}
